#include "PlanePart.h"




PlanePart::PlanePart(Vector3d pos,Vector3d norm,Vector3d plane_start,Vector3d plane_end,bool ix,bool iy,bool iz) : Plane(pos,norm),start(plane_start),end(plane_end),x(ix),y(iy),z(iz)
{
}


PlanePart::~PlanePart(void)
{
}



inline bool rsmaller(double &a,double &b)
{
	return (a) < (b); 
}

inline bool rbigger(double &a,double &b)
{
	return (a) > (b); 
}

TraceResult PlanePart::collision(const Ray &ray)
{
	TraceResult tr = Plane::collision(ray);

	//ignore x
	if(x)
	{
		if(rsmaller(tr.point.y,end.y) && rbigger(tr.point.y,start.y) && rsmaller(tr.point.z,end.z) && rbigger(tr.point.z,start.z))
			return tr;
		else
			return TraceResult::empty;
	}

	//ignore y
	if(y)
	{
		if(rsmaller(tr.point.x,end.x) && rbigger(tr.point.x,start.x) && rsmaller(tr.point.z,end.z) && rbigger(tr.point.z,start.z))
			return tr;
		else
			return TraceResult::empty;
	}

	//ignore z
	if(z)
	{
		if(rsmaller(tr.point.y,end.y) && rbigger(tr.point.y,start.y) && rsmaller(tr.point.x,end.x) && rbigger(tr.point.x,start.x))
			return tr;
		else
			return TraceResult::empty;
	}
	return TraceResult();
}